package com.woniu.petkonwledge.controller;

import com.woniu.common.entity.QuestionBank;
import com.woniu.common.entity.ResponseResult;
import com.woniu.petkonwledge.service.QuestionBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/questionBank")
public class QuestionBankController {
    @Autowired
    QuestionBankService questionBankService;
    //随机从题库获取十道题
    @ResponseBody
    @RequestMapping("/getQuestion")
    public ResponseResult<List<QuestionBank>> getQuestion(){
        ResponseResult<List<QuestionBank>> result = new ResponseResult<>();
        List<QuestionBank> questionBanks = null;
        try {
            questionBanks = questionBankService.getQuestion();
        }catch (Exception e){
            result.setCode(400);
            result.setMessage("查询错误");
            throw e;

        }
        result.setCode(200);
        result.setMessage("ok");
        result.setData(questionBanks);
        return result;
    }
}
